const directiveFiles = require.context('./', true, /index.js$/)

const directives = directiveFiles.keys().filter(key => key !== './index.js').reduce((modules, modulePath) => {
  const moduleName = modulePath.replace(/^\.\/(.*)\/index.\w+$/, '$1')
  const value = directiveFiles(modulePath)
  modules[moduleName] = value.default
  return modules
}, {})

export default {
  install: Vue => {
    for (const key in directives) {
      Vue.use(directives[key])
    }
  }
}
